import api from "../api/index";
import Axios from '../utils/axios'


export interface queryObject {
    advertisingName?: string,
    position?: string,
    limit?: number,
    page?: number
}

// 获取广告列表
function getAdverList() {
    return Axios.get(api.settings.ADVER_SELECT)
}

// 查询广告
function queryAdver(obj: queryObject) {
    let txtData = "?"
    for (let key in obj) {
        txtData += `${key}=${obj[key]}&`
    }
    txtData = txtData.slice(0, txtData.length - 1)
    console.log("请求参数：", txtData)
    return Axios.get(api.settings.ADVER_QUERY, { params: obj })
}

// 根据id获取
function getAdverById(id: any) {
    return Axios.get(api.settings.ADVER_GET_BY_ID + id)
}

// 添加广告
function addAdver(obj: object) {
    console.log("请求传参", obj)
    return Axios.post(api.settings.ADVER_INSERT, obj)
}


// 修改广告
function updateAdver(obj: object) {
    return Axios.post(api.settings.ADVER_UPDATE, obj)
}

// 根据id删除
function deleteById(id: any) {
    return Axios.get(api.settings.ADVER_DELETE_ID, { params: { id } })
}



export default {
    getAdverList,
    getAdverById,
    addAdver,
    updateAdver,
    queryAdver,
    deleteById,
}